package com.example.administrator.uitest.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.uitest.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Maker on 2019/4/14.
 */

public class ListAdapter extends BaseAdapter {
    private List<Map<String,String>> data;
    private Context context;
    private boolean flag;
    public ListAdapter(List<Map<String,String>> data,Context context,boolean flag){
        this.data = data;
        this.flag = flag;
        this.context = context;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view == null){
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.list_item,null);
            viewHolder.hit = view.findViewById(R.id.hit);
            viewHolder.shoot = view.findViewById(R.id.shoot);
            viewHolder.time = view.findViewById(R.id.time);
            viewHolder.userId = view.findViewById(R.id.user);
            viewHolder.change = view.findViewById(R.id.change);
            viewHolder.item = view.findViewById(R.id.item);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (flag){
            viewHolder.change.setVisibility(View.GONE);
        }else {
            viewHolder.change.setVisibility(View.VISIBLE);
        }
        viewHolder.item.setText(""+(i+1));
        viewHolder.hit.setText(data.get(i).get("hit"));
        viewHolder.shoot.setText(data.get(i).get("shoot"));
        viewHolder.time.setText(data.get(i).get("time"));
        viewHolder.userId.setText(data.get(i).get("userId"));
        return view;
    }
    class ViewHolder{
        TextView time;
        TextView userId;
        TextView shoot;
        TextView hit;
        LinearLayout change;
        TextView item;
    }
}
